package com.edan.partnerback.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edan.partnerback.common.VO.DynamicCache;
import com.edan.partnerback.entity.Dynamic;
import com.edan.partnerback.mapper.DynamicMapper;
import com.edan.partnerback.service.IDynamicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author edan
 * @since 2024-03-28
 */
@Service
public class DynamicServiceImpl extends ServiceImpl<DynamicMapper, Dynamic> implements IDynamicService {
    @Resource
    DynamicMapper dynamicMapper;

    @Override
    public Set<DynamicCache> listDynamicsAll(String type) {
        Set<DynamicCache> dynamics = dynamicMapper.selecViewsAll(type);
        Set<DynamicCache> comments = dynamicMapper.selectComments();
        dynamics.forEach(dynamic -> comments.stream()
                .filter(dynamic::equals)
                .findFirst().ifPresent(dynamicCache -> dynamic.setComments(dynamicCache.getComments())));
        return dynamics;
    }

    @Override
    public List<Dynamic> listByIdsPart(List<Integer> ids) {
        return dynamicMapper.selectAllByIds(ids);
    }
}
